﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wicresoft.UnifyShow.Business;
using Oracle.DataAccess.Client;
using System.Data;

namespace Wicresoft.UnifyShow.BusinessImpl
{
    public class Configuration : Basic, IConfiguration
    {
        private const string sqlUpdateKey = "UPDATE configuration SET cof_value = :VALUE WHERE cof_key=:KEY";
        public string GetValueByKey(string key)
        {
            string value = string.Empty;
            QueryParameter[] attParam = new QueryParameter[] {
                    new QueryParameter(){ OracleDbColumnName="COF_KEY", OracleDbColumnType=OracleDbType.NVarchar2, OracleDbColumnSize=50,
                        OracleDbColumnValue=key,QueryOperator=QueryOperatorType.equal,PredicateType=PredicateType.where},
                    };
            ConfigurationModel item = ModelHelper<ConfigurationModel>.GetModel_By_QueryParams(attParam, null, null, null, oda).FirstOrDefault();
            if (item != null)
            {
                value = item.COF_VALUE;
            }
            else
            {
                value = "0";
            }
            return value;
        }

        public void UpdateKey(string key, string value)
        {
            ModelHelper<ConfigurationModel>.UpdateOrDeleteModel_By_DirectSql(sqlUpdateKey, new List<OracleParameter>(){         
            new OracleParameter(){ParameterName="KEY",OracleDbType=OracleDbType.NVarchar2,Size=40,Value=key,Direction=ParameterDirection.Input},
            new OracleParameter(){ParameterName="VALUE",OracleDbType=OracleDbType.NVarchar2,Size=40,Value=value,Direction=ParameterDirection.Input}
            }, oda);
        }
    }
}
